define(["jquery", "./scheduleInit.js", "./scheduleCon.js", "./lang_en.js", "./lang_zh.js", "../lib/tips/message.js","./init.js"], function ($, scheduleInit, scheduleCon, en, zh, $message,summary) {
    var load = function (tid, bajaObj) {
        $message.message();
        var data = JSON.parse(bajaObj.getJsonData());
        // 设置语言
        if ("language" in data.item) {
            if (data.item["language"] == "zh") {
                var languageData = zh.languageData;
            } else if (data.item["language"] == "en") {
                var languageData = en.languageData;
            }
        } else {
            var languageData = zh.languageData;
        }
        // 设置主题
        window.document.documentElement.setAttribute("data-theme", "defaultTheme");
        // window.document.documentElement.setAttribute("data-theme", "themeFirst");
        // console.log(languageData);
        $("#" + tid).css({
            "width": "100%",
            "height": "100%"
        });
        var str = `<!-- 整体内容 -->
    <div id="schedule">
        <ul id="scheduleHeader">
            <li class="sel">${languageData.weeklySchedule}</li>
            <li>${languageData.specialEvent}</li>
            <li>${languageData.summary}</li>
            <li style="display:none;">${languageData.calendarSchedule}</li>
            <div id="selectBlock"></div>
        </ul>
        <!-- 周日成表 -->
        <div id="weekSchedule" class="contentData">
            <div class="topCon">            
                <ul class="timeList">
                    <li>&nbsp;</li>
                    <li>03:00</li>
                    <li>06:00</li>
                    <li>09:00</li>
                    <li>12:00</li>
                    <li>15:00</li>
                    <li>18:00</li>
                    <li>21:00</li>
                    <li>&nbsp;</li>
                </ul>

                <div id="scheduleRoot" class="scheduleRoot">
                    <!-- 左1列div -->
                    <div data-type="root0" class="blocksRoot root0" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root1" class="blocksRoot root1" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root2" class="blocksRoot root2" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root3" class="blocksRoot root3" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root4" class="blocksRoot root4" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root5" class="blocksRoot root5" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
        
                    <!-- 左2列div -->
                    <div data-type="root6" class="blocksRoot root6" >
                        <div data-type="block" class="block block0"></div>
                        <div data-type="block" class="block block1"></div>
                        <div data-type="block" class="block block2"></div>
                        <div data-type="block" class="block block3"></div>
                        <div data-type="block" class="block block4"></div>
                        <div data-type="block" class="block block5"></div>
                        <div data-type="block" class="block block6"></div>
                        <div data-type="block" class="block block7"></div>
                    </div>
                </div>
            </div>
            <div class="bottomCon">
                <ul>
                    <li class="firstLi">周日</li>
                    <li>周一</li>
                    <li>周二</li>
                    <li>周三</li>
                    <li>周四</li>
                    <li>周五</li>
                    <li>周六</li>
                </ul>
            </div>
            <div class="controlCon">
                <ul class="timeUl">
                    <li>
                        <p class="timeP">${languageData.eventStar}</p>
                        <select name="" id="" class="hourList startHour">
                            
                        </select>
                        <select name="" id="" class="minuteList startMinute">
                            
                        </select>
                    </li>
                    <li>
                        <p class="timeP endTimeP">${languageData.eventEnd}</p>
                        <select name="" id="" class="hourList endHour">
                            
                        </select>
                        <select name="" id="" class="minuteList endMinute">
                            
                        </select>
                    </li>
                </ul>
                <ul class="tingUl">
                    <li class='selectOrInput'>
                        <p class="timeP">${languageData.eventOutput}</p>
                        <select class="selectThing tingOut" name="" id="">
                            <!-- <option value=true>true</option> -->
                            <!-- <option value=false>false</option> -->
                        </select>
                        <input class="inputThing tingOut" id="" type='text' />
                        <span class="spanUnit"></span>
                    </li>
                    <li>
                        <input type="checkbox" name="isEmpty2" class='isEmpty' id="isEmpty2">
                        <label for="isEmpty2">${languageData.null}</label>
                    </li>
                    <li class="buttonLi">
                        <div class="button" id="saveButton" title="${languageData.saveButton}"><span class="iconfont icon-fuzhi"></span></div>
                        <div class="button" id="reload" title="${languageData.refreshButton}"><span class="iconfont icon-shuaxin"></span></div>
                        
                    </li>
                </ul>
            </div>
        </div>
        <!-- 特殊日程表 -->
        <div id="specialSchedule" class="contentData">
            <div class='topDiv'>
                <div id="specialLeft">
                    <ul class="dateContent">
                        <li class="dateHeard">
                            <span class='lastMonth iconfont icon-jiantou-zuo'></span>
                            <span class='jumpToday'>${languageData.now}</span>
                            <span class="showDate"></span>
                            <span class='nextMonth iconfont icon-jiantou-you'></span>
                        </li>
                        <li class="weekList">
                            <p>${languageData.weekList[0]}</p>
                            <p>${languageData.weekList[1]}</p>
                            <p>${languageData.weekList[2]}</p>
                            <p>${languageData.weekList[3]}</p>
                            <p>${languageData.weekList[4]}</p>
                            <p>${languageData.weekList[5]}</p>
                            <p>${languageData.weekList[6]}</p>
                        </li>
                        <li class="weekContent week0">
                            
                        </li>
                        <li  class="weekContent week1">
                            
                        </li>
                        <li class="weekContent week2">
                            
                        </li>
                        <li class="weekContent week3">
                            
                        </li>
                        <li class="weekContent week4">
                            
                        </li>
                        <li class="weekContent week5">
                            
                        </li>
                    </ul>
                    <div id="addButton"> + ${languageData.add}</div>
                </div>
                <div id='specialCenter'>
                    <dl class='specialList'>
                        <dt>${languageData.eventList}</dt>
                        <div>
                            
                        </div>
                    </dl>
                    <div id='operation'>
                        <span class='iconfont icon-icon-- toTop disabled' title=${languageData.toTop}></span>
                        <span class='iconfont icon-icon--1 toBottom disabled' title=${languageData.toBottom}></span>
                        <span class='iconfont icon-icon_edit toEdit disabled' title=${languageData.toEdit}></span>
                        <span class='iconfont icon-chongmingming toReanme disabled' title=${languageData.toRename}></span>
                        <span class='iconfont icon-shanchu toDelete disabled' title=${languageData.toDelete}></span>
                    </div>
                </div>
                <div id='specialRight'>
                    <div class='topRight'>
                        <ul class="timeList">
                            <li>&nbsp;</li>
                            <li>03:00</li>
                            <li>06:00</li>
                            <li>09:00</li>
                            <li>12:00</li>
                            <li>15:00</li>
                            <li>18:00</li>
                            <li>21:00</li>
                            <li>&nbsp;</li>
                        </ul>
                        <div class='scheduleRoot otherRoot' id="scheduleRootOther">
                            <div data-type="root7" class="blocksRoot root7" >
                                <div data-type="block" class="block block0"></div>
                                <div data-type="block" class="block block1"></div>
                                <div data-type="block" class="block block2"></div>
                                <div data-type="block" class="block block3"></div>
                                <div data-type="block" class="block block4"></div>
                                <div data-type="block" class="block block5"></div>
                                <div data-type="block" class="block block6"></div>
                                <div data-type="block" class="block block7"></div>
                            </div>
                        </div>
                        
                    </div>
                    <div class='bottomRight'>
                        <div class="controlCon">
                            <ul class="timeUl">
                                <li>
                                    <p class="timeP">${languageData.eventStar}</p>
                                    <select name=""  class="hourList startHour"><option value="00">00时</option><option value="01">01时</option><option value="02">02时</option><option value="03">03时</option><option value="04">04时</option><option value="05">05时</option><option value="06">06时</option><option value="07">07时</option><option value="08">08时</option><option value="09">09时</option><option value="10">10时</option><option value="11">11时</option><option value="12">12时</option><option value="13">13时</option><option value="14">14时</option><option value="15">15时</option><option value="16">16时</option><option value="17">17时</option><option value="18">18时</option><option value="19">19时</option><option value="20">20时</option><option value="21">21时</option><option value="22">22时</option><option value="23">23时</option><option value="24">24时</option></select>
                                    <select name=""  class="minuteList startMinute"><option value="00">00分</option><option value="01">01分</option><option value="02">02分</option><option value="03">03分</option><option value="04">04分</option><option value="05">05分</option><option value="06">06分</option><option value="07">07分</option><option value="08">08分</option><option value="09">09分</option><option value="10">10分</option><option value="11">11分</option><option value="12">12分</option><option value="13">13分</option><option value="14">14分</option><option value="15">15分</option><option value="16">16分</option><option value="17">17分</option><option value="18">18分</option><option value="19">19分</option><option value="20">20分</option><option value="21">21分</option><option value="22">22分</option><option value="23">23分</option><option value="24">24分</option><option value="25">25分</option><option value="26">26分</option><option value="27">27分</option><option value="28">28分</option><option value="29">29分</option><option value="30">30分</option><option value="31">31分</option><option value="32">32分</option><option value="33">33分</option><option value="34">34分</option><option value="35">35分</option><option value="36">36分</option><option value="37">37分</option><option value="38">38分</option><option value="39">39分</option><option value="40">40分</option><option value="41">41分</option><option value="42">42分</option><option value="43">43分</option><option value="44">44分</option><option value="45">45分</option><option value="46">46分</option><option value="47">47分</option><option value="48">48分</option><option value="49">49分</option><option value="50">50分</option><option value="51">51分</option><option value="52">52分</option><option value="53">53分</option><option value="54">54分</option><option value="55">55分</option><option value="56">56分</option><option value="57">57分</option><option value="58">58分</option><option value="59">59分</option></select>
                                </li>
                                <li>
                                    <p class="timeP endTimeP">${languageData.eventEnd}</p>
                                    <select name=""  class="hourList endHour"><option value="00">00时</option><option value="01">01时</option><option value="02">02时</option><option value="03">03时</option><option value="04">04时</option><option value="05">05时</option><option value="06">06时</option><option value="07">07时</option><option value="08">08时</option><option value="09">09时</option><option value="10">10时</option><option value="11">11时</option><option value="12">12时</option><option value="13">13时</option><option value="14">14时</option><option value="15">15时</option><option value="16">16时</option><option value="17">17时</option><option value="18">18时</option><option value="19">19时</option><option value="20">20时</option><option value="21">21时</option><option value="22">22时</option><option value="23">23时</option><option value="24">24时</option></select>
                                    <select name=""  class="minuteList endMinute"><option value="00">00分</option><option value="01">01分</option><option value="02">02分</option><option value="03">03分</option><option value="04">04分</option><option value="05">05分</option><option value="06">06分</option><option value="07">07分</option><option value="08">08分</option><option value="09">09分</option><option value="10">10分</option><option value="11">11分</option><option value="12">12分</option><option value="13">13分</option><option value="14">14分</option><option value="15">15分</option><option value="16">16分</option><option value="17">17分</option><option value="18">18分</option><option value="19">19分</option><option value="20">20分</option><option value="21">21分</option><option value="22">22分</option><option value="23">23分</option><option value="24">24分</option><option value="25">25分</option><option value="26">26分</option><option value="27">27分</option><option value="28">28分</option><option value="29">29分</option><option value="30">30分</option><option value="31">31分</option><option value="32">32分</option><option value="33">33分</option><option value="34">34分</option><option value="35">35分</option><option value="36">36分</option><option value="37">37分</option><option value="38">38分</option><option value="39">39分</option><option value="40">40分</option><option value="41">41分</option><option value="42">42分</option><option value="43">43分</option><option value="44">44分</option><option value="45">45分</option><option value="46">46分</option><option value="47">47分</option><option value="48">48分</option><option value="49">49分</option><option value="50">50分</option><option value="51">51分</option><option value="52">52分</option><option value="53">53分</option><option value="54">54分</option><option value="55">55分</option><option value="56">56分</option><option value="57">57分</option><option value="58">58分</option><option value="59">59分</option></select>
                                </li>
                            </ul>
                            <ul class="tingUl">
                                <li class="selectOrInput">
                                    <p class="timeP">${languageData.eventOutput}</p>
                                    <input type="checkbox" name="isEmpty" class='isEmpty' id="isEmpty1">
                                    <label for="isEmpty1">${languageData.null}</label>
                                    <select class="selectThing tingOut" name="" id="">
                                        <!-- <option value=true>true</option> -->
                                        <!-- <option value=false>false</option> -->
                                    </select>
                                    <input class="inputThing tingOut"  type="number">
                                    <span class="spanUnit"></span>
                                    
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class='bottomDiv'>
                <div class='saveSpiceButton' title="${languageData.saveButton}"><span class="iconfont icon-fuzhi"></span></div>
                <div class="reloadSpiceButton" title="${languageData.refreshButton}"><span class="iconfont icon-shuaxin"></span></div>
            </div>
        </div>
        <!-- 日程总览 -->
        <div id="overviewSchedule" class="contentData">
        <div class='topDiv'>
        <div id="specialLeft">
            <ul class="dateContent">
                <li class="dateHeard">
                    <span class='lastMonth iconfont icon-jiantou-zuo'></span>
                    <span class='jumpToday1 jumpToday'>${languageData.now}</span>
                    <span class="showDate"></span>
                    <span class='nextMonth iconfont icon-jiantou-you'></span>
                </li>
                <li class="weekList">
                    <p>${languageData.weekList[0]}</p>
                    <p>${languageData.weekList[1]}</p>
                    <p>${languageData.weekList[2]}</p>
                    <p>${languageData.weekList[3]}</p>
                    <p>${languageData.weekList[4]}</p>
                    <p>${languageData.weekList[5]}</p>
                    <p>${languageData.weekList[6]}</p>
                </li>
                <li class="weekContent week0">
                    
                </li>
                <li  class="weekContent week1">
                    
                </li>
                <li class="weekContent week2">
                    
                </li>
                <li class="weekContent week3">
                    
                </li>
                <li class="weekContent week4">
                    
                </li>
                <li class="weekContent week5">
                    
                </li>
            </ul>
           
        </div>
        <div id='specialCenter'>
            <dl class='specialList'>
                <dt>${languageData.eventList}</dt>
                <div>
                    <!--<dd>
                        <ul class="ptop">
                            <li class='ball'>
                                <span></span>
                            </li>
                            <li class="time">
                                <span class="iconfont icon-time"></span>
                                <span class="timeText">时间:</span>
                                <span class="timeCont">2020/04/01 00:00</span>
                            </li>
                            <li class="type">
                                <span class="iconfont icon-liuchengshijian"></span>
                                <span class="timeText">类别:</span>
                                <span class="timeCont">周日程</span>
                            </li>
                        </ul>
                        <ul class="eventUl">
                            <li class="time eventText">
                                <span class="iconfont icon-liuchengshijian"></span>
                                <span class="timeText">事件:</span>
                                <span class="timeCont">开启</span>
                            </li>
                        </ul>
                    </dd> -->
                </div>
            </dl>
           
        </div>
        
    </div>
    <div class='bottomDiv'>
        
        <div class="reloadSpiceButton" title="${languageData.refreshButton}"><span class="iconfont icon-shuaxin"></span></div>
    </div>
        </div>
    </div>
    
    <!--新建特殊事件弹窗-->
    <div class="blockDate newEvent">
    <div class='dateSelectDiv'>
        <div class='closeButton'>
            <span class='dataTitle'></span>
            <span class='iconfont icon-guanbi coloseX'></span>
        </div>
        <ul>
            <li class='dataName'>
                <p>${languageData.evnetName}</p>
                <input type="text" class='dateText'>
            </li>
            <li class='dataType'>
                <p>${languageData.type}</p>
                <select class='dataSelect'>
                    
                </select>
            </li>
            <li class='dataOne'>
                <select class='dateOneYear'>

                </select>
                <select class='dateOneMonth'>

                </select>
                <select class='dateOneDate'>

                </select>
                <select class='dateOneDay'>

                </select>
            </li>
            <li class='dataRang'>
                <div>
                    <select class='dateOneYear yearStart'></select>
                    <select class='dateOneMonth monthStart'></select>
                    <select class='dateOneDate dateStart'></select>
                </div>
                <p>${languageData.to}</p>
                <div>
                    <select class='dateOneYear yearEnd'></select>
                    <select class='dateOneMonth monthEnd'></select>
                    <select class='dateOneDate dateEnd'></select>
                </div>
            </li>
            <li class='reference'>
                <select class='referenceSelect'></select>
            </li>
        </ul>
        <div class="foot">
            <div class='buttonDiv cancelButton'>${languageData.cancel}</div>
            <div class='buttonDiv confirmButton'>${languageData.confirm}</div>
        </div>
    </div>
    </div>
    
    <div class="blockDate setDate">
        <div class='dateSelectDiv'>
            <div class='closeButton'>
                <span class='dataTitle'></span>
                <span class='iconfont icon-guanbi coloseX'></span>
            </div>
            <ul>
                <li class='dataOne'>
                    <select class='dateOneYear notAnyYear'>

                    </select>
                    <select class='dateOneMonth notAnyMonth'>

                    </select>
                </li>
            </ul>
            <div class="foot">
                
                <div class='buttonDiv setButton'>${languageData.setButton}</div>
            </div>
        </div>
    </div>
    <!-- 删除特殊日程 -->
    <div class="blockDate deleteDate">
        <div class='dateSelectDiv'>
            <div class='closeButton'>
                <span class='iconfont icon-guanbi coloseX'></span>
            </div>
            <ul>
                <p class="deleteCon"></p>
            </ul>
            <div class="foot">
                <div class='buttonDiv cancelButton'>${languageData.cancel}</div>
                <div class='buttonDiv deleteButton'>${languageData.confirmOther}</div>
            </div>
        </div>
    </div>
    <!-- 重命名 -->
    <div class="blockDate renameDate">
        <div class='dateSelectDiv'>
            <div class='closeButton'>
                <span class='iconfont icon-guanbi coloseX'></span>
            </div>
            <ul>
                <li class="dataName">
                    <p>${languageData.scheduleName}</p>
                    <input type="text" class="dateText">
                </li>
            </ul>
            <div class="foot">
                <div class='buttonDiv cancelButton'>${languageData.cancel}</div>
                <div class='buttonDiv renameButton'>${languageData.confirmOther}</div>
            </div>
        </div>
    </div> 

    <!--右键菜单-->
    <div id="divmenu" class="menu">
        <ul>
            <li id='copyLi' >${languageData.copy}</li>
            <li id="psateLi" class="disabledPaste">${languageData.past}</li>
            <li id='removeLi'>${languageData.delete}</li>
            <span class="line"></span>
            <li id='removeDayLi'>${languageData.clearDay}</li>
            <li id='removeWeekLi'>${languageData.clearWeek}</li>
            <span class="line"></span>
            <li id='checkDayLi'>${languageData.allDay}</li>
            <li id='copyMToFLi'>${languageData.applyMF}</li>
            <li id='defaultLi'>${languageData.default}</li>
        </ul>
    </div>`;
        $("#" + tid).append(str);
        if(data.item["language"] == "en"){
            // $(".jumpToday").css("width","32px")
            $(".jumpToday").css({"width":"32px","left":"38px"});
        }
        $('.contentData').hide();
        $("#weekSchedule").show();
        // 全局颜色设置
        var globalColor = {
            true: "",
            false: "fasleitem",
            null: "nullitem",
            list: ["color1", "color2", "color3", "color4", "color5", "color6", "color7", "color8", "color9", "color10", "color11"],
        };
        var scheduleType = "";
        if (data.responseCommand == "Ok") {
            // 下拉框中的值
            if ("scheduleType" in data.item) {
                scheduleType = data.item.scheduleType;
                if (scheduleType == "StringSchedule" || scheduleType == "NumericSchedule") { //等于string和number
                    $(".selectThing").remove();
                } else { // 枚举和布尔
                    $(".inputThing").remove();
                }
                if (scheduleType == "NumericSchedule") {
                    $(".inputThing").attr("type", "number").val(0);

                } else if (scheduleType == "StringSchedule") {
                    $(".inputThing").attr("type", "text");
                }
                // 如果是数值类型，添加单位
                if(scheduleType == "NumericSchedule"){
                    $(".spanUnit").text(data.item.unit);
                }
            }

            if ("eventOutputs" in data.item) {
                // 如果是布尔类型，更改显示
                if (scheduleType == "BooleanSchedule") {
                    for (var i = 0; i < data.item.eventOutputs.length; i++) {
                        if (data.item.eventOutputs[i]["key"] == "trueText") {
                            data.item.eventOutputs[i]["key"] = true;
                        } else if (data.item.eventOutputs[i]["key"] == "falseText") {
                            data.item.eventOutputs[i]["key"] = false;
                        }
                    }
                }
                var str = "";
                if(data.item.eventOutputs.length==0){
                    data.item.eventOutputs.push({
                        key:0,
                        value:0
                    })
                }
                for (var i = 0; i < data.item.eventOutputs.length; i++) {
                    var now_data = data.item.eventOutputs[i];
                    var val = now_data.key;
                    str += "<option  value='" + val + "'>" + now_data.value + "</option>";
                }
                

                $(".tingOut").empty().append(str);
            }

            // 周日到周六赋值,ord赋值
            function pullDataToTime(data) {
                if ("weekPlans" in data.item) {
                    for (var i = 0; i < data.item.weekPlans.length; i++) {
                        var now_data = data.item.weekPlans[i];
                        $(".bottomCon").find("li").eq(i).text(now_data.text);
                        $(".root" + i).attr("ord", now_data["ord"]);

                        var str = "";
                        for (var j = 0; j < now_data.events.length; j++) {
                            var this_data = now_data.events[j];
                            if (scheduleType == "EnumSchedule") { // 枚举类型
                                var index = 0;
                                for (var k = 0; k < data.item.eventOutputs.length; k++) {
                                    if (this_data.effectiveValue == Number(data.item.eventOutputs[k]["key"])) {
                                        index = k;
                                    }
                                }
                                var colorItem = globalColor["list"][index % 11];
                                var thing = computerThing(this_data['effectiveValue']);
                            } else if (scheduleType == "BooleanSchedule") { //布尔类型
                                var colorItem = globalColor[this_data.effectiveValue];
                                var thing = computerThing(this_data['effectiveValue']);
                            } else if (scheduleType == "StringSchedule") { //字符串类型
                                var colorItem = '';
                                var thing = this_data['effectiveValue'];
                            }else if(scheduleType == "NumericSchedule"){ // 数字类型
                                var colorItem = '';
                                if(this_data['effectiveValue']=="null"){
                                    var thing = "null";
                                }else{
                                    var thing = this_data['effectiveValue'] + " " +data.item.unit;
                                }
                            }
                            if (this_data.effectiveValue == "null") {
                                var colorItem = "nullitem"
                            }
                            var finish = this_data['finish'].split(' ')[0] == "00:00" ? "24:00" : this_data['finish'].split(' ')[0];// 结束时间等于00:00的时候，格式化成为24：00
                            var start = this_data['start'].split(' ')[0];
                            if (computerTimeRang(start, finish) < 1 * 60 * 60 * 1000) {
                                str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(this_data['start'])}" data-end="${changeTimeToTimestamp(this_data['finish'])}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(this_data['finish'], 'bottom')}; top: ${changTimeToTopAndBottom(this_data['start'], 'top')};">
                                            <div class="eventItem" style="cursor: pointer;">
                                                <span class="thing" style="display:none;">${thing}</span><br/>
                                                <span class="start" style="display:none;">${start}</span>-<span style="display:none;" class="end">${finish}</span>
                                            </div>
                                        </div>`
                            } else if (computerTimeRang(start, finish) > 1 * 60 * 60 * 1000 && computerTimeRang(start, finish) < 2 * 60 * 60 * 1000) {
                                str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(this_data['start'])}" data-end="${changeTimeToTimestamp(this_data['finish'])}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(this_data['finish'], 'bottom')}; top: ${changTimeToTopAndBottom(this_data['start'], 'top')};">
                                            <div class="eventItem" style="cursor: pointer;">
                                                <span class="thing">${thing}</span><br/>
                                                <span class="start" style="display:none;">${start}</span>-<span style="display:none;" class="end">${finish}</span>
                                            </div>
                                        </div>`
                            } else {
                                str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(this_data['start'])}" data-end="${changeTimeToTimestamp(this_data['finish'])}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(this_data['finish'], 'bottom')}; top: ${changTimeToTopAndBottom(this_data['start'], 'top')};">
                                            <div class="eventItem" style="cursor: pointer;">
                                                <span class="thing">${thing}</span><br/>
                                                <span class="start">${start}</span>-<span class="end">${finish}</span>
                                            </div>
                                        </div>`
                            }


                        }
                        $(".root" + i).append(str);
                    }
                }
            }
            pullDataToTime(data);
            // 计算返回的下拉框中的事件
            function computerThing(params) { // 通过value获取到key
                var thing = "null";
                if (scheduleType == "BooleanSchedule" || scheduleType == "EnumSchedule") {
                    for (var i = 0; i < data.item.eventOutputs.length; i++) {
                        if (params == String(data.item.eventOutputs[i]["key"])) {
                            thing = data.item.eventOutputs[i]["value"];
                        }
                    }
                    if(params!="null" && thing=="null"){
                        thing = params;
                    }
                } else {
                    return params;
                }
                return thing;
            }
            function computerThingBack(params) { // 通过key来获取value
                var thing = "null";
                if (scheduleType == "BooleanSchedule" || scheduleType == "EnumSchedule") {
                    for (var i = 0; i < data.item.eventOutputs.length; i++) {
                        if (params == String(data.item.eventOutputs[i]["value"])) {
                            thing = String(data.item.eventOutputs[i]["key"]);
                        }
                    }
                } else {
                    if(scheduleType=="NumericSchedule"){
                        return parseFloat(params)
                    }else{
                        return  params;
                    }
                }
                return thing;
            }
            // 计算两个时间的间隔
            function computerTimeRang(start, end) {
                var startTime = new Date();
                var endTime = new Date();
                startTime.setHours(start.split(":")[0]);
                startTime.setMinutes(start.split(":")[1]);
                startTime.setSeconds(0);
                startTime.setMilliseconds(0);
                endTime.setHours(end.split(":")[0]);
                endTime.setMinutes(end.split(":")[1]);
                endTime.setSeconds(0);
                endTime.setMilliseconds(0);
                endTime = endTime.getTime();
                startTime = startTime.getTime();
                // console.log(startTime,endTime);
                return endTime - startTime;
            }

            //根据时间改为时间戳
            function changeTimeToTimestamp(time) {
                var timeCon = time.split(" ")[0];
                var startHour = timeCon.split(":")[0];
                var startMinute = timeCon.split(":")[1];
                var startTime = new Date();
                startTime.setHours(startHour);
                startTime.setMinutes(startMinute);
                startTime.setSeconds(0);
                startTime.setMilliseconds(0);
                // console.log(startTime.getTime())
                return startTime.getTime();
            }
            // 根据时间计算出来top 和 bottom
            function changTimeToTopAndBottom(time, sign) {
                var timeCon = time.split(" ")[0];
                var amOrPm = time.split(" ")[1]
                var startHour = Number(timeCon.split(":")[0]);
                var startMinute = Number(timeCon.split(":")[1]);
                // console.log(startHour, startMinute, sign)
                var returnValue = "";
                if (sign == "top") {
                    returnValue = (100 * (60 * startHour + startMinute) / 1440).toFixed(4) + '%';
                } else if (sign == "bottom") {
                    if (startHour == 0 && startMinute == 0) {
                        startHour = 24;
                    }
                    returnValue = (100 * (1440 - 60 * startHour - startMinute) / 1440).toFixed(4) + '%';
                }
                // console.log(returnValue);
                return returnValue;
            }

        }
        scheduleInit.load1(data, globalColor);
        // 点击保存按钮
        $("#saveButton").click(function () {
            saveFunction();
        })
        var timeArr = [];
        var postData = {
            item: {
                scheduleType: data.item.scheduleType,
                weekPlans: ""
            }
        };
        function saveFunction() {
            timeArr.length = 0;
            for (var i = 0; i < 7; i++) {
                var arr = [];
                for (var j = 0; j < $(".root" + i).find(".event").length; j++) {
                    var bomDiv = $(".root" + i).find(".event")[j];
                    var startTime = $(bomDiv).find(".start").text()
                    var start = startTime.split(":")[0] > 12 ? startTime + " PM" : startTime + " AM";
                    var endTime = $(bomDiv).find(".end").text();
                    if (endTime == "24:00") {
                        endTime = "00:00";
                    }
                    var finish = endTime.split(":")[0] > 12 ? endTime + " PM" : endTime + " AM";
                    arr.push({
                        start: start,
                        finish: finish,
                        effectiveValue: computerThingBack($(bomDiv).find(".thing").text())
                    })
                }
                timeArr.push({
                    text: data.item.weekPlans[i].text,
                    ord: data.item.weekPlans[i].ord,
                    events: arr
                });
            }
            postData.item.weekPlans = timeArr;
            // console.log(postData);
            bajaObj.ajax(postData, ajaxSuccess, ajaxError);
        }
        // 点击刷新
        $("#reload").unbind("click").click(function () {
            // console.log("点击了刷新");
            bajaObj.ajax({
                item: {
                    background: null,
                    scheduleOrd: data.item.scheduleOrd,
                    type: "readWeeklySchedule"
                },
                showType: "RefreshWeekly"
            }, reloadSuccess, reloadErr);
            addDisabled();
            setTimeNow();
        })
        function setTimeNow() {
            var now = new Date();
            var hour = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
            var min = now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
            $(".startHour").val(hour);
            $(".startMinute").val(min);
            $(".endHour").val(hour);
            $(".endMinute").val(min);
        }
        function reloadSuccess(data) {
            // console.log(data);
            $("#scheduleRoot .event ").remove();
            pullDataToTime(data);
        }
        function reloadErr(data) {
            // console.log(data);
        }
        // 成功函数
        function ajaxSuccess(msg) {
            $.message(languageData.saveSuccess);
        }
        function ajaxError(msg) {

        }
        function subDisabled() {
            $(".startHour").attr("disabled", false);
            $(".startMinute").attr("disabled", false);
            $(".endHour").attr("disabled", false);
            $(".endMinute").attr("disabled", false);
            $(".tingOut").attr("disabled", false);
            $(".isEmpty").attr("disabled", false);
        }
        function addDisabled() {
            $(".startHour").attr("disabled", true);
            $(".startMinute").attr("disabled", true);
            $(".endHour").attr("disabled", true);
            $(".endMinute").attr("disabled", true);
            $(".tingOut").attr("disabled", true);
            $(".isEmpty").attr("disabled", true);
        }
        addDisabled();// 刚进来，让所有的输入框不可选

        // 点击头部
        $("#scheduleHeader li").click(function () {
            var defaultValue = 12; // 下面的横杠比上面的文字宽的部分
            var boxWidth = $("#scheduleHeader").offset().left;
            var index = $(this).index();
            $("#scheduleHeader li").removeClass("sel");
            $(this).addClass("sel");
            var thisWidth = $(this).width();
            var leftValue = $(this).offset().left;
            // console.log('leftValue: ', leftValue);
            $('.contentData').hide();
            var selectBlockLeft = leftValue - boxWidth - defaultValue / 2;
            var scaleNumber = $("#root").width()/1000; // 计算现在缩放的倍数
            if(scaleNumber<1){
                if(scaleNumber<=0.5){ // 小于0.5之后就缩放了
                    scaleNumber = 0.5;
                }
                selectBlockLeft = selectBlockLeft / scaleNumber;
            }
            if (index == 0) {
                $("#weekSchedule").show();
            } else if (index == 1) {
                $("#specialRight").show();// 让右侧的事件表显示
                $(".bottomDiv").show();// 让最下面的保存按钮显示
                $("#specialSchedule").show();
                getSpiceData();
            } else if (index == 2) {
                $("#overviewSchedule").show();
                // getAllData();
                summary.load(bajaObj,);
            } else if (index == 3) {
                $("#specialRight").hide();// 让右侧的事件表隐藏
                $(".bottomDiv").hide();// 让最下面的保存按钮隐藏
                $("#specialSchedule").show();

            }
            $("#selectBlock").width(thisWidth + defaultValue);
            $("#selectBlock").css("left", selectBlockLeft + "px");
        })
        var msg = "";
        // 判断如果是特殊日程
        if (data.item.scheduleType == "CalendarSchedule") {
            $("#scheduleHeader li:lt(3)").hide();
            $("#scheduleHeader li").eq(3).show();
            $("#scheduleHeader li").eq(3).css("margin-left", "31px");
            $("#scheduleHeader li").eq(3).click();
            // console.log(data);
            msg = data;
            scheduleCon.load2(bajaObj, data, globalColor, selectOrd);
        } else {
            $("#scheduleHeader li").eq(0).click();
        }
        function getSpiceData() {
            bajaObj.ajax({
                showType: "ReadSpecial"
            }, SpecialajaxSuccess, ajaxError);
        }

        ////////////////////////////////////////////////////特殊日程
        // 特殊日程获取时间成功
        function SpecialajaxSuccess(msg1) {
            msg = msg1;
            scheduleCon.load2(bajaObj, msg1, globalColor, selectOrd, $(".showDate").eq(0).text(), selectChangType);
        }
        // 点击确认按钮
        $(".confirmButton").click(function () {
            if ($(".dataTitle").hasClass("hide")) { // 隐藏了， 证明就是新增
                addEvent();
            } else { // 没有隐藏，证明是编辑
                editEvent();
            }
        })
        // 点击确认按钮（新增）
        function addEvent() {
            var eventName = $(".dateText").val();
            var eventDateType = $(".dataSelect").val();
            if (eventName == "") {
                $.message({
                    message: languageData.enterName,
                    type: "warning"
                })
                return;
            }
            var jsonData = {};
            jsonData.specialPlanType = eventDateType;
            if (eventDateType == "Date") {
                computerDate(jsonData);
                if ("error" in jsonData) {
                    return;
                }
            } else if (eventDateType == "DateRange") {
                var yearStart = $(".yearStart").val();
                var yearEnd = $(".yearEnd").val();
                var monthStart = $(".monthStart").val();
                if (monthStart != -1) {
                    monthStart--;
                }
                var monthEnd = $(".monthEnd").val();
                if (monthEnd != -1) {
                    monthEnd--;
                }
                var dayStart = $(".dateStart").val();
                var dayEnd = $(".dateEnd").val();
                // console.log("获取到的结束日期",yearEnd,monthEnd,dayEnd)
                // 如果结束事件是现在以前的日期，则需要报错
                if(yearEnd!=-1&&monthEnd!=-1){
                    if(yearEnd < new Date().getFullYear()){
                        $.message({
                            message: languageData.DateErrorLast,
                            type: "warning"
                        })
                        return;
                    }
                    if(yearEnd == new Date().getFullYear() && monthEnd < new Date().getMonth()){
                        $.message({
                            message: languageData.DateErrorLast,
                            type: "warning"
                        })
                        return;
                    }
                }
                if(monthStart==3||monthStart==5||monthStart==8||monthStart==10){
                    if(dayStart==31){
                        $.message({
                            message: languageData.DateError,
                            type: "warning"
                        })
                        return;
                    }
                }
                if(monthEnd==3||monthEnd==5||monthEnd==8||monthEnd==10){
                    if(dayEnd==31){
                        $.message({
                            message: languageData.DateError,
                            type: "warning"
                        })
                        return;
                    }
                }
                if (monthStart == 1) {
                    if (yearStart != -1) {
                        // console.log("不是任意年")
                        if (yearStart % 4 == 0 && yearStart % 100 != 0 || yearStart % 400 == 0) {
                            // console.log("闰年")
                            if (dayStart >= 30) {
                                $.message({
                                    message: languageData.DateError,
                                    type: "warning"
                                })
                                jsonData.error = "error";
                                return;
                            }
                        } else {
                            if (dayStart >= 29) {
                                $.message({
                                    message: languageData.DateError,
                                    type: "warning"
                                })
                                jsonData.error = "error";
                                return;
                            }
                        }
                    } else {
                        if (dayStart >= 29) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    }
                }

                if (monthEnd == 1) {
                    if (yearEnd != -1) {
                        // console.log("不是任意年")
                        if (yearEnd % 4 == 0 && yearEnd % 100 != 0 || yearEnd % 400 == 0) {
                            // console.log("闰年")
                            if (dayEnd >= 30) {
                                $.message({
                                    message: languageData.DateError,
                                    type: "warning"
                                })
                                jsonData.error = "error";
                                return;
                            }
                        } else {
                            if (dayEnd >= 29) {
                                $.message({
                                    message: languageData.DateError,
                                    type: "warning"
                                })
                                jsonData.error = "error";
                                return;
                            }
                        }
                    } else {
                        if (dayEnd >= 29) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    }
                }

                if(yearEnd!=-1&&monthEnd!=-1&&dayEnd!=-1){
                    var selectTime = new Date(yearEnd, monthEnd, dayEnd, 23, 59, 59).getTime();
                    var nowTime = new Date().getTime();
                    if (selectTime < nowTime) {
                        $.message({
                            message: languageData.DateErrorLast,
                            type: "warning"
                        })
                        jsonData.error = "error";
                        return;
                    }
                }
                if (yearEnd!=-1 && yearStart > yearEnd) {
                    jsonData.error = "error";
                    $.message({
                        message: languageData.timeError,
                        type: "warning"
                    })
                    return;
                }
                if (yearStart != -1 && yearEnd != -1 && monthStart != -1 && monthEnd != -1) {
                    if(yearStart == yearEnd){
                        if (monthStart > monthEnd) {
                            jsonData.error = "error";
                            $.message({
                                message: languageData.timeError,
                                type: "warning"
                            })
                            return;
                        }
                        if (monthStart == monthEnd && dayStart != -1 && dayEnd != -1) {
                            if (Number(dayStart) > Number(dayEnd)) {
                                jsonData.error = "error";
                                $.message({
                                    message: languageData.timeError,
                                    type: "warning"
                                })
                                return;
                            }
                        }
                    }else if(yearStart > yearEnd){
                        jsonData.error = "error";
                        $.message({
                            message: languageData.timeError,
                            type: "warning"
                        })
                        return;
                    }
                }

                jsonData.weekdayEnd = -1;
                jsonData.weekdayStart = -1;
                jsonData.yearStart = yearStart;
                jsonData.yearEnd = yearEnd;
                jsonData.monthStart = monthStart;
                jsonData.monthEnd = monthEnd;
                jsonData.dayStart = dayStart;
                jsonData.dayEnd = dayEnd;

            } else if (eventDateType == "Reference") {
                computerReference(jsonData);
                if ("error" in jsonData) {
                    return;
                }
            }
            jsonData.events = [];
            jsonData.text = eventName;
            jsonData.ord = "";
            // console.log(jsonData);
            postAjax("add", jsonData);// 发送ajax
        }

        // 点击确认按钮（编辑时间）
        function editEvent() {
            // console.log("编辑时间", selectOrd);
            var jsonData = {};
            for (var i = 0; i < msg.item.specialPlans.length; i++) {
                var nowData = msg.item.specialPlans[i];
                if (nowData.ord == selectOrd) {
                    jsonData = nowData;
                }
            }

            if (jsonData.specialPlanType == "Date") {
                computerDate(jsonData);
                if ("error" in jsonData) {
                    return;
                }
            } else if (jsonData.specialPlanType == "DateRange") {
                computerDateRange(jsonData);
                if ("error" in jsonData) {
                    return;
                }
            } else if (jsonData.specialPlanType == "Reference") {
                computerReference(jsonData);
                if ("error" in jsonData) {
                    return;
                }
            }
            postAjax("edit", jsonData);
        }
        // 发送请求
        function postAjax(operate, jsonData) {
            // console.log(msg);
            var cloneMsg = JSON.parse(JSON.stringify(msg));
            // console.log(cloneMsg);
            cloneMsg.item.specialPlans.length = 0;
            cloneMsg.item.operate = operate;
            cloneMsg.item.specialPlans.push(jsonData);
            var postData = {
                showType: "WriteSpecial",
                item: cloneMsg.item
            }
            postData.item.eventOutputs = [];//清空
            // console.log("最后传输给后台的数据",postData);
            selectChangType = operate;
            bajaObj.ajax(postData, success, ajaxError);
        }
        // Date的数据整理
        function computerDate(jsonData) {
            delete jsonData.error;
            var year = $(".dataOne .dateOneYear").val();
            var month = $(".dataOne .dateOneMonth").val();
            var date = $(".dataOne .dateOneDate").val();
            var day = $(".dataOne .dateOneDay").val();

            if (month == 2) {
                if (year != -1) {
                    // console.log("不是任意年")
                    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                        // console.log("闰年")
                        if (date >= 30) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    } else {
                        if (date >= 29) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    }
                } else {
                    if (date >= 29) {
                        $.message({
                            message: languageData.DateError,
                            type: "warning"
                        })
                        jsonData.error = "error";
                        return;
                    }
                }
            }
            // 选择的4，6，9，11，不能选择31号
            if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (date == 31) {
                    $.message({
                        message: languageData.DateError,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if (year != -1 && month != -1 && date != -1 && day != -1) {
                if (new Date(year, month - 1, date).getDay() != day) {
                    $.message({
                        message: languageData.DateError,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if (year != -1 && month != -1 && date != -1) {
                var selectTime = new Date(year, month - 1, date, 23, 59, 59).getTime();
                var nowTime = new Date().getTime();
                if (selectTime < nowTime) {
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if(year != -1 && month !=-1){
                if(year < new Date().getFullYear()){
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
                if(year == new Date().getFullYear() && month < (new Date().getMonth()+1) ){
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }

            if (month != -1) {
                month--;
            }
            jsonData.yearStart = year;
            jsonData.monthStart = month;
            jsonData.dayStart = date;
            jsonData.weekdayStart = day;
        }
        // DateRange的数据整理
        function computerDateRange(jsonData) {
            delete jsonData.error;
            var yearStart = $(".yearStart").val();
            var yearEnd = $(".yearEnd").val();
            var monthStart = $(".monthStart").val();
            var monthEnd = $(".monthEnd").val();
            var dayStart = $(".dateStart").val();
            var dayEnd = $(".dateEnd").val();
            if(monthStart!=-1){
                monthStart --;
            }
            if(monthEnd!=-1){
                monthEnd -- ;
            }
            // console.log("开始日期",yearStart,monthStart,dayStart);
            // console.log("结束日期",yearEnd,monthEnd,dayEnd);
            if(yearEnd!=-1&&monthEnd!=-1){
                if(yearEnd < new Date().getFullYear()){
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
                if(yearEnd == new Date().getFullYear() && monthEnd < new Date().getMonth()){
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if(monthStart==3||monthStart==5||monthStart==8||monthStart==10){
                if(dayStart==31){
                    $.message({
                        message: languageData.DateError,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if(monthEnd==3||monthEnd==5||monthEnd==8||monthEnd==10){
                if(dayEnd==31){
                    $.message({
                        message: languageData.DateError,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if (monthStart == 1) {
                if (yearStart != -1) {
                    // console.log("不是任意年")
                    if (yearStart % 4 == 0 && yearStart % 100 != 0 || yearStart % 400 == 0) {
                        // console.log("闰年")
                        if (dayStart >= 30) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    } else {
                        if (dayStart >= 29) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    }
                } else {
                    if (dayStart >= 29) {
                        $.message({
                            message: languageData.DateError,
                            type: "warning"
                        })
                        jsonData.error = "error";
                        return;
                    }
                }
            }

            if (monthEnd == 1) {
                if (yearEnd != -1) {
                    // console.log("不是任意年")
                    if (yearEnd % 4 == 0 && yearEnd % 100 != 0 || yearEnd % 400 == 0) {
                        // console.log("闰年")
                        if (dayEnd >= 30) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    } else {
                        if (dayEnd >= 29) {
                            $.message({
                                message: languageData.DateError,
                                type: "warning"
                            })
                            jsonData.error = "error";
                            return;
                        }
                    }
                } else {
                    if (dayEnd >= 29) {
                        $.message({
                            message: languageData.DateError,
                            type: "warning"
                        })
                        jsonData.error = "error";
                        return;
                    }
                }
            }


            if(yearEnd!=-1&&monthEnd!=-1&&dayEnd!=-1){
                var selectTime = new Date(yearEnd, monthEnd, dayEnd, 23, 59, 59).getTime();
                var nowTime = new Date().getTime();
                if (selectTime < nowTime) {
                    $.message({
                        message: languageData.DateErrorLast,
                        type: "warning"
                    })
                    jsonData.error = "error";
                    return;
                }
            }
            if (yearEnd!=-1 && yearStart > yearEnd) {
                jsonData.error = "error";
                $.message({
                    message: languageData.timeError,
                    type: "warning"
                })
                return;
            }
            if (yearStart != -1 && yearEnd != -1 && monthStart != -1 && monthEnd != -1) {
                if(yearStart == yearEnd){
                    if (monthStart > monthEnd) {
                        jsonData.error = "error";
                        $.message({
                            message: languageData.timeError,
                            type: "warning"
                        })
                        return;
                    }
                    if (monthStart == monthEnd && dayStart != -1 && dayEnd != -1) {
                        if (Number(dayStart) > Number(dayEnd)) {
                            jsonData.error = "error";
                            $.message({
                                message: languageData.timeError,
                                type: "warning"
                            })
                            return;
                        }
                    }
                }else if(yearStart > yearEnd){
                    jsonData.error = "error";
                    $.message({
                        message: languageData.timeError,
                        type: "warning"
                    })
                    return;
                }
            }
            jsonData.yearStart = yearStart;
            jsonData.yearEnd = yearEnd;
            jsonData.monthStart = monthStart;
            jsonData.monthEnd = monthEnd;
            jsonData.dayStart = dayStart;
            jsonData.dayEnd = dayEnd;
            jsonData.weekdayEnd = "-1";
            jsonData.weekdayStart = "-1";
        }
        // Reference的数据整理
        function computerReference(jsonData) {
            delete jsonData.error;
            jsonData.specialPlanType = "Reference";
            jsonData.ref = $(".referenceSelect").val();
        }
        function success(respone) {
            if (respone.responseCommand == "Ok") {
                // console.log("现在弹窗的状态",selectChangType);
                $(".newEvent").hide();
                if (selectChangType == "delete") {
                    $(".deleteDate").hide();
                    $.message(languageData.deleteSuccess);
                } else if (selectChangType == "rename") {
                    $.message(languageData.renameSuccess);
                    $(".renameDate").hide();
                } else if (selectChangType == "edit") {
                    $.message(languageData.editSuccess);
                } else if (selectChangType == "timeSave") {
                    $.message(languageData.saveSuccess);
                } else if (selectChangType == "priority") {
                    // console.log("调整位置成功");
                } else if (selectChangType == "add") {
                    $.message(languageData.addSuccess);
                }
                getSpiceData();
            }
        }
        function ajaxError(err) {
            // console.log("进入到ajaxError")
            if ("responseMessage" in err) {
                $.message({
                    type: "warning",
                    message: err.responseMessage
                })
            } else {
                $.message({
                    type: "warning",
                    message: languageData.addFaild
                })
            }
        }
        var selectOrd = ""; // 
        var selectChangType = ""; // 现在的状态
        // 删除按钮
        $(".toDelete").click(function () {
            if ($(this).hasClass("disabled")) {
                return;
            } else {
                var eventName = $(".specialList .selected").find("span").eq(1).text();
                $(".deleteDate .dateSelectDiv").css({"width":"480px","height":"220px"});
                $(".deleteDate ul").css({"margin-top":"0"});
                $(".deleteDate .dataName").show();
                $(".deleteCon").text(languageData.deleteContent+eventName+languageData.deleteContentOther);
                $(".deleteDate").removeClass("dialogHide").addClass("dialogShow");
                $(".deleteDate").show();
            }
        })

        $(".deleteButton").click(function(){
            var ord = $(".specialList .selected").attr("ord");
            var postData = {
                item: {},
                showType: "WriteSpecial"
            };
            postData.item.background = msg.item.background;
            postData.item.eventOutputs = [];
            postData.item.ord = msg.item.ord;
            postData.item.scheduleType = msg.item.scheduleType;
            postData.item.specialPlans = [];
            postData.item.operate = "delete";
            var jsonData = {};
            jsonData.ord = ord;
            // jsonData.operate = "delete";
            postData.item.specialPlans.push(jsonData);
            selectChangType = "delete";
            bajaObj.ajax(postData, success, ajaxError);
        })

        // 重命名按钮
        $(".toReanme").click(function () {
            if ($(this).hasClass("disabled")) {
                return;
            } else {
                var eventName = $(".specialList .selected").find("span").eq(1).text();
                // console.log(eventName);
                $(".renameDate .dateSelectDiv").css({"width":"480px","height":"220px"});
                $(".renameDate ul").css({"margin-top":"0"});
                $(".renameDate .dataName").show();
                $(".renameDate").find('.dateText').val(eventName);
                $(".renameDate").show();
                $(".renameDate").removeClass("dialogHide").addClass("dialogShow");
            }
        })
        $(".renameButton").click(function(){
            var ord = $(".specialList .selected").attr("ord");
            var name = $(".renameDate").find('.dateText').val();
            if (name != null && name != "") {
                var postData = {
                    item: {},
                    showType: "WriteSpecial"
                };
                postData.item.background = msg.item.background;
                postData.item.eventOutputs = [];
                postData.item.ord = msg.item.ord;
                postData.item.scheduleType = msg.item.scheduleType;
                postData.item.specialPlans = [];
                postData.item.operate = "rename";
                var jsonData = {};
                jsonData.ord = ord;
                jsonData.text = name;
                postData.item.specialPlans.push(jsonData);
                selectChangType = "rename";
                bajaObj.ajax(postData, success, ajaxError);
            }
        })
        // 双击事件
        $(".specialList").on("dblclick", "dd", function () {
            selectOrd = $(this).attr("ord");
            // console.log(selectOrd)
        })
        // 编辑时间
        $(".toEdit").click(function () {
            if ($(this).hasClass("disabled")) {
                return;
            } else {
                var thisValue = $(".specialList .selected").attr("specialPlanType");
                var oldName = $(".specialList .selected").find("span:not('.ball')").text();
                var ord = $(".specialList .selected").attr("ord");
                selectOrd = ord;
                // console.log(thisValue, oldName);
                pullDate(ord);
                $(".dataTitle").text(oldName).removeClass("hide");
                if (thisValue == "Date") {
                    $(".dataRang").hide();
                    $(".reference").hide();
                    $(".dateSelectDiv").height(153);
                    $(".dataOne").show();
                } else if (thisValue == "DateRange") {
                    $(".reference").hide();
                    $(".dataOne").hide();
                    $(".dateSelectDiv").height(220);
                    $(".dataRang").show();
                } else if (thisValue == "Reference") {
                    $(".referenceSelect").val()
                    $(".dataOne").hide();
                    $(".dataRang").hide();
                    $(".dateSelectDiv").height(153);
                    $(".reference").show();
                }
                // 隐藏上面两个li
                $(".newEvent .dataName").hide();
                $(".dataType").hide();
                $(".dateSelectDiv ul").css("margin-top", "15px");
                $(".newEvent").removeClass("dialogHide").addClass("dialogShow");
                $(".newEvent").show();
            }
        })
        // 大保存的按钮
        $(".saveSpiceButton").click(function () {
            var selectedEvent = $(".specialList .selected");
            var ord = selectedEvent.attr("ord");
            selectOrd = ord;
            var events = $(".root7 .event");
            if (selectedEvent.length == 0 || events.length == 0) { // 没有选中的话，直接retuen
                // console.log("什么都没有保存的，直接return")
                return;
            }
            selectChangType = "timeSave";
            var timeArr = [];
            var arr = [];
            for (var j = 0; j < events.length; j++) {
                var bomDiv = events[j];
                var startTime = $(bomDiv).find(".start").text()
                var start = startTime.split(":")[0] > 12 ? startTime + " PM" : startTime + " AM";
                var endTime = $(bomDiv).find(".end").text();
                var finish = endTime.split(":")[0] > 12 ? endTime + " PM" : endTime + " AM";
                finish = finish == "24:00 PM" ? "00:00 AM" : finish;
                arr.push({
                    start: start,
                    finish: finish,
                    effectiveValue: computerThingBack($(bomDiv).find(".thing").text())
                })
            }
            timeArr.push({
                ord: ord,
                events: arr
            });
            // console.log(timeArr);
            var postData = {
                item: {},
                showType: "WriteSpecial"
            };
            postData.item.background = msg.item.background;
            postData.item.eventOutputs = [];
            postData.item.ord = msg.item.ord;
            postData.item.scheduleType = msg.item.scheduleType;
            postData.item.specialPlans = [];
            postData.item.operate = "save";
            postData.item.specialPlans[0] = timeArr[0];
            // console.log(postData);
            bajaObj.ajax(postData, success, ajaxError);
        })
        // 点击刷新页面
        $(".reloadSpiceButton").unbind("click").click(function () {
            getSpiceData();
            $(".isEmpty").attr("disabled", true);
            $(".tingOut").attr("disabled", true);
        })
        // 点击上下的按钮，调整位置
        $(".toTop").click(function () {
            // console.log("点击向上的按钮");
            if ($(this).hasClass("disabled")) {
                return;
            }
            moveEvents(-1);
        })
        $(".toBottom").click(function () {
            // console.log("点击向下的按钮");
            if ($(this).hasClass("disabled")) {
                return;
            }
            moveEvents(1);
        })
        function moveEvents(step) {
            var selectedEvent = $(".specialList .selected");
            var ord = selectedEvent.attr("ord");
            selectOrd = ord;
            var index = selectedEvent.index();
            if (selectedEvent.length == 0) {
                return;
            }
            var postData = {
                item: {},
                showType: "WriteSpecial"
            };
            postData.item.background = msg.item.background;
            postData.item.eventOutputs = [];
            postData.item.ord = msg.item.ord;
            postData.item.scheduleType = msg.item.scheduleType;
            postData.item.specialPlans = [];
            postData.item.operate = "priority";
            selectChangType = "priority";
            var oldArr = [];
            msg.item.specialPlans.map(item => {
                oldArr.push({
                    ord: item.ord
                })
            })

            oldArr.splice(index, 1);
            oldArr.splice(index + Number(step), 0, {
                ord: ord
            })
            postData.item.specialPlans = oldArr;
            bajaObj.ajax(postData, success, ajaxError);
        }


        // 让原来选中的时间，继续选中
        function pullDate(ord) {
            for (var i = 0; i < msg.item.specialPlans.length; i++) {
                var nowData = msg.item.specialPlans[i];
                if (nowData.ord == ord) {
                    // console.log(nowData)
                    var thisValue = nowData.specialPlanType;
                    if (thisValue == "Date") {
                        $(".dataOne .dateOneYear").val(nowData.yearStart);
                        if (nowData.monthStart == -1) {
                            $(".dataOne .dateOneMonth").val(Number(nowData.monthStart));
                        } else {
                            $(".dataOne .dateOneMonth").val(Number(nowData.monthStart) + 1);
                        }
                        $(".dataOne .dateOneDate").val(nowData.dayStart);
                        $(".dataOne .dateOneDay").val(nowData.weekdayStart);
                    } else if (thisValue == "DateRange") {
                        $(".yearStart").val(nowData.yearStart);
                        $(".yearEnd").val(nowData.yearEnd);
                        if (nowData.monthStart == -1) {
                            $(".monthStart").val(Number(nowData.monthStart));
                        } else {
                            $(".monthStart").val(Number(nowData.monthStart) + 1);
                        }
                        if (nowData.monthEnd == -1) {
                            $(".monthEnd").val(Number(nowData.monthEnd));
                        } else {
                            $(".monthEnd").val(Number(nowData.monthEnd) + 1);
                        }
                        $(".dateStart").val(nowData.dayStart);
                        $(".dateEnd").val(nowData.dayEnd);
                    } else if (thisValue == "Reference") {
                        $(".referenceSelect").val(nowData.ref);
                    }
                }
            }
        }
        // 默认事件
        $("#defaultLi").click(function (e) {
            defaultEvent();
        })
        Date.prototype.Format = function (fmt) { //author: meizz
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
        function defaultEvent() {
            if($(".root7").hasClass("default")){
                return;
            }
            var events = $(".root7").find(".event");
            // console.log(events);
            var arr = [];
            var oldArr = []
            for (var i = 0; i < events.length; i++) {
                var nowData = events.eq(i);
                // console.log(nowData.attr("data-start"))
                var start = new Date(Number(nowData.attr("data-start")));
                var end = new Date(Number(nowData.attr("data-end")));
                arr.push((start.getHours()) * 60 + start.getMinutes());
                if ((end.getHours() == 0) && (end.getMinutes() == 0)) {
                    arr.push(1440);
                    oldArr.push({
                        start: (start.getHours()) * 60 + start.getMinutes(),
                        end: 1440
                    })
                } else {
                    arr.push((end.getHours()) * 60 + end.getMinutes());
                    oldArr.push({
                        start: (start.getHours()) * 60 + start.getMinutes(),
                        end: (end.getHours()) * 60 + end.getMinutes()
                    })
                }
            }
            arr.sort(function (a, b) {
                return a - b;
            })
            // 如果第一开始不是0，就给添加一个
            if (arr[0] != 0) {
                arr.splice(0, 0, 0);
            }
            // 最后一个事件不是24：00，就给添加一个
            if (arr[arr.length - 1] != 1440) {
                arr.push(1440);
            }
            // console.log(arr);
            // console.log(oldArr);
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                var startMinute = arr[i];
                var endMinute = arr[i + 1];
                // console.log(startMinute,endMinute);
                var flage = 0;
                for (var j = 0; j < oldArr.length; j++) {
                    if (oldArr[j].start == startMinute && oldArr[j].end == endMinute) {
                        flage--;
                    } else {
                        flage++;
                    }
                }
                if (flage == oldArr.length) { // 这样就能创建一个新的事件了
                    var startTime = new Date();
                    startTime.setHours(parseInt(startMinute / 60));
                    startTime.setMinutes(startMinute % 60);
                    startTime.setSeconds(0);
                    startTime.setMilliseconds(0);
                    var endTime = new Date();
                    endTime.setHours(parseInt(endMinute / 60));
                    endTime.setMinutes(endMinute % 60);
                    endTime.setSeconds(0);
                    endTime.setMilliseconds(0);
                    // console.log(scheduleType);
                    if(scheduleType=="BooleanSchedule"){
                        var colorItem = "fasleitem";
                        var thing = data.item.eventOutputs[1].value;
                    }else{
                        var thing = "null";
                        var colorItem = "nullitem";
                    }

                    var finish = endTime.Format("HH:mm") == "00:00" ? "24:00" : endTime.Format("HH:mm");// 结束时间等于00:00的时候，格式化成为24：00
                    var start = startTime.Format("HH:mm");
                    var startPMAM = startTime.Format("HH") > 12 ? start + " PM" : start + " AM";
                    var endPMAM = finish.split(":")[0] > 12 ? finish + " PM" : finish + " AM";
                    if(start==finish){
                        return;
                    }

                    if (computerTimeRang(start, finish) < 1 * 60 * 60 * 1000) {
                        str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(startPMAM)}" data-end="${changeTimeToTimestamp(endPMAM)}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(endPMAM, 'bottom')}; top: ${changTimeToTopAndBottom(startPMAM, 'top')};">
                                <div class="eventItem" style="cursor: pointer;">
                                    <span class="thing" style="display:none;">${thing}</span><br/>
                                    <span class="start" style="display:none;">${start}</span>-<span style="display:none;" class="end">${finish}</span>
                                </div>
                            </div>`
                    } else if (computerTimeRang(start, finish) > 1 * 60 * 60 * 1000 && computerTimeRang(start, finish) < 2 * 60 * 60 * 1000) {
                        str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(startPMAM)}" data-end="${changeTimeToTimestamp(endPMAM)}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(endPMAM, 'bottom')}; top: ${changTimeToTopAndBottom(startPMAM, 'top')};">
                                <div class="eventItem" style="cursor: pointer;">
                                    <span class="thing">${thing}</span><br/>
                                    <span class="start" style="display:none;">${start}</span>-<span style="display:none;" class="end">${finish}</span>
                                </div>
                            </div>`
                    } else {
                        str += `<div title='${thing + "\n" + start + "-" + finish}' data-start="${changeTimeToTimestamp(startPMAM)}" data-end="${changeTimeToTimestamp(endPMAM)}" class="event ${colorItem}" style="bottom: ${changTimeToTopAndBottom(endPMAM, 'bottom')}; top: ${changTimeToTopAndBottom(startPMAM, 'top')};">
                                <div class="eventItem" style="cursor: pointer;">
                                    <span class="thing">${thing}</span><br/>
                                    <span class="start">${start}</span>-<span class="end">${finish}</span>               
                                </div>
                            </div>`
                    }
                }
                if (i == arr.length - 2) {
                    break;
                }
            }
            // console.log(str);
            $(".root7").append(str)
            $(".root7").addClass("default");
        }
    };
    return {
        load: load
    }
});